<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>签到</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <script src="/js/jquery/jquery.min.js"></script>
    <link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css">
    <script src="/js/bootstrap/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css">
    <link rel="stylesheet" href="/css/reset.css" rel="stylesheet">
    <link rel="stylesheet" href="/css/index.css" rel="stylesheet">
    <script src="../js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="../js/plugins/dialog2/dialog.css">
    <script src="../js/plugins/dialog2/dialog.min.js"></script>

    <link rel="stylesheet" href="../sign/sign2.css">


</head>
<body>
<div class="search-head">
    <div class="row nav-search">
        <div class="col">
            <a href="javascript:history.go(-1);">
                <span><i class="fa fa-chevron-left"></i></span>
            </a>
        </div>
    </div>
</div>

<div class="container news">
    <div class="news" id="dailyContent">
        <script src="../sign/calendar2.js"></script>
    </div>
</div>
<div style="" id="calendar">

</div>
<div>
    <button id="sign" type="button" class="btn btn-primary btn-lg btn-block">签到</button>
</div>
<div id="sign_note" style="text-align:center;position: relative;padding: 15px;    font-size: 14px;">
    <span style="color:red;">*规则</span><br>
    <span style="color:red;">签到一天积分加100</span><br>
    <span style="color:red;">连续签到3天积分额外加500</span><br>
    <span style="color:red;">连续签到3天开宝箱</span>
</div>

<script type="text/javascript">
    $(function () {
        var signList = [];
        var date = new Date();
        $.get("/sign", function (data) {
            //判断当前用户是否有签到过,用于已签到的数据回显
            if (data != 1) {
                for (var i = 0; i < data.length; i++) {
                    signList.push(data[i]);
                }
                //签到后刷新页面将签到按钮改成已签到
                if (data[data.length - 1].signDay == date.getDate()) {
                    $("#sign").html("已签到");
                    $("#sign").attr("class","btn btn-success btn-lg btn-block");
                }
            }
            //初始化日历
            calUtil.init(signList);
        });


        $("#sign").click(function () {
            //当前用户为第一次签到或当天首次签到
            if (signList.length == 1 || signList[signList.length - 1].signDay < date.getDate()) {
                signList.push({"signDay": date.getDate()});
                //重新初始化日历
                calUtil.init(signList);

                $("#sign").html("已签到");
                $("#sign").attr("class","btn btn-success btn-lg btn-block");
                $(document).dialog({
                    type: 'notice',
                    infoText: '签到成功,积分加100',
                    autoClose: 1500,
                    position: 'bottom'  // center: 居中; bottom: 底部
                });
                //进行积分添加
                $.post("/sign/updateIntegral",{integral:100});


                //------------------------------------>
                var num = '';
                for (var i = 0; i < signList.length; i++) {
                    if (signList[i].signDay) {
                        num += signList[i].signDay + ",";
                    }
                }
                //保存签到数据
                $.post("/sign/saveOrUpdate", {signDay: num});


                //判断是否连续三天签到
                var max = signList[signList.length - 1].signDay;
                var two = signList[signList.length - 2].signDay;
                var one = signList[signList.length - 3].signDay;

                if (max - 1 == two && max - 2 == one) {
                    $.post("/sign/updateIntegral",{integral:600});
                    $(document).dialog({
                        type: 'toast',
                        infoText: '你已连续签到三天,积分额外加500',
                        autoClose: 2000
                    });
                }

            } else {
                $(document).dialog({
                    type: 'notice',
                    infoText: '你已签到',
                    autoClose: 2000,
                    position: 'bottom'  // center: 居中; bottom: 底部
                });
            }

        });


    });
</script>
</body>
</html>